import Vue from 'vue'
import App from './views/layout/App'
import router from './router'
import store from './store'
import axios from './backend'
import filters from './filters'
import directives from './directives'
import globalMixin from './mixins'
import components from './components/base'
import { debounce } from 'lodash'

import VCharts from 'v-charts'

import SessionStorage from '@vue-common/utils/session-storage'
import LocalStorage from '@vue-common/utils/local-storage'

import './plugins'
// 导入Icon
import '@/icons'

import '@/assets/styles/index.less'

Vue.config.productionTip = false

// 将axios注册成为Vue原型属性
Vue.prototype.http = axios

Vue.prototype.$SessionStorage = SessionStorage
Vue.prototype.$LocalStorage = LocalStorage

// ===============================================
// 注册过滤器
// ===============================================
for (const key in filters) {
  if (Object.hasOwnProperty.call(filters, key)) {
    Vue.filter(key, filters[key])
  }
}
// ===============================================
// 注册指令
// ===============================================
for (const key in directives) {
  if (Object.hasOwnProperty.call(directives, key)) {
    Vue.use(directives[key], {
      store
    })
  }
}

// ===============================================
// 注册全局组件
// ===============================================
Vue.use(components)
Vue.use(VCharts)

// ===============================================
// 窗体改变事件
// ===============================================
const onresize = debounce(() => {
  store.dispatch('window/Resize')
}, 100)

window.onresize = onresize

/* eslint-disable no-new */
// new Vue({
//   el: '#app',
//   router,
//   store,
//   render: h => h(App),
//   mounted () {
//     console.log('-------------------App 挂载')
//     // initUserRouterAndMenu()
//     this.$store.dispatch('app/InitRouterAndMenu')
//   }
// })

Vue.mixin(globalMixin)

store.dispatch('user/GetUserInfo').then((result) => {
  setTimeout(() => {
    new Vue({
      router,
      store,
      render: h => h(App)
    }).$mount('#app')
  }, 500)
})
